﻿using JWT;
using JWT.Exceptions;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using SmartWMS.Common;
using SmartWMS.Common.Jwt;
using SmartWMS.Common.ResponseOutput;
using SmartWMS.Domain.Base;
using SmartWMS.Domain.SystemSet;
using SmartWMS.Server.SystemSets.MenuServices;
using SmartWMS.Server.SystemSets.MenuServices.Dto;

namespace SmartWMS.API.Controllers.SystemSet
{
    /// <summary>
    /// 导航菜单
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    [ApiExplorerSettings(GroupName = "XTong")]
    public class MenuController : ControllerBase
    {
        private readonly IMenuService _menuService;
        public MenuController(IMenuService menuService)
        {
            _menuService = menuService;
        }

        /// <summary>
        /// 五表联查获取权限树
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        /// <summary>
        /// 导航菜单
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        [HttpPost]
        public IActionResult GetmenuById(KeyEntity key)
        {
            var resault = _menuService.GetmenuByIdAsync(key);

            return Ok(resault.Result);
        }

        /// <summary>
        /// 权限菜单树
        /// </summary>
        /// <param name="pId"></param>
        /// <returns></returns>
        [HttpPost]
        public IActionResult GetPermissionTree(int pId)
        {
            var result = _menuService.GetPermissionTree(pId);
            return Ok(result);
        }
        /// <summary>
        /// 菜单权限添加
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<Response<bool>> AddPermissionTree(MenuInput input)
        {
            var result = _menuService.AddPermissionTreeAsync(input);
            return result.Result;
        }
        /// <summary>
        /// 菜单权限修改
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<Response<bool>> UpdatePermissionTree(MenuInput input)
        {
            var result = _menuService.UpdatePermissionTreeAsync(input);
            return result.Result;
        }
        /// <summary>
        /// 菜单权限反填
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<Response<MenuInput>> GetPermissionById(KeyEntity key)
        {
            var result = _menuService.GetPermissionByIdAsync(key);
            return result.Result;
        }
        /// <summary>
        /// 获取全部权限
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public IActionResult GetAllPermission()
        {
            var result = _menuService.GetAllPermissionAsync();
            return Ok(result.Result);
        }

    }

}
